package com.tgq.demo.common;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;


/**
 * 加密类
 */
public class EncryptionSymmetric {
    /**
     * 加密方法
     * @return
     */
    private static SymmetricCrypto MyEncryptionMethod(){
        // 16位自定义密码 必须为16位
        String key = "1!3+56/891=1112*";
        // 生成密钥
        byte[] byteKey = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue(), key.getBytes()).getEncoded();
        SymmetricCrypto aes = SecureUtil.aes(byteKey);
        return aes;
    }
    /**
     * 加密
     * @param Password
     * @return
     */
    public static String Encryption(String Password){
        SymmetricCrypto aes = MyEncryptionMethod();
        // 加密
        String encryptData = aes.encryptBase64(Password);
        System.out.println(encryptData);
        return encryptData;
    }

    /**
     * 解密
     * @param Password
     * @return
     */
    public static String Decrypt(String Password){
        SymmetricCrypto aes = MyEncryptionMethod();
        // 解密
        String decryptData = aes.decryptStr(Password);
        System.out.println(decryptData);
        return decryptData;
    }
}
